// ./`rollup.config.js`
import path from "path";
import babel from "@rollup/plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import sourceMaps from "rollup-plugin-sourcemaps";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import livereload from "rollup-plugin-livereload"; // hot
import serve from "rollup-plugin-serve";

export default {
  input: "./src/index.ts",

  output: [
    {
      name: "iota-utools",
      dir: path.join("lib/cjs"),
      format: "cjs",
      preserveModules: true,
      preserveModulesRoot: "src",
    },
    {
      name: "iota-utools",
      dir: path.join("lib/es"),
      format: "es",
      preserveModules: true, // 保留模块结构
      preserveModulesRoot: "src", // 将保留的模块放在根级别的此路径下
    },
  ],

  plugins: [
    resolve({
      // 将自定义选项传递给解析插件
      customResolveOptions: {
        moduleDirectory: "node_modules",
      },
    }),
    commonjs(),
    typescript(),
    sourceMaps(),
    livereload(),
    babel({
      runtimeHelpers: true,
      // 只转换源代码，不运行外部依赖
      exclude: "node_modules/**",
      babelHelpers: "bundled",
    }),
    serve({
      open: true,
      port: 10801,
      contentBase: ["", "./public"],
    }),
  ],
};
